'''获取安乡建设项目环评'''

# http://zw.yrcc.gov.cn/zwxxlist.jsp?bm=1120100


import requests
import codecs
import os
from bs4 import BeautifulSoup as bs
import cssselect
from lxml.html import etree
import re


# https://www.anxiang.gov.cn/xxgk/zfxxgkml/jdjcqk/hjbh/jsxmhp


n = 25    # 25
m = 0
for x in range(n):
    x = x + 1
    r = requests.get('https://www.anxiang.gov.cn/xxgk/zfxxgkml/jdjcqk/hjbh/jsxmhp_%s' %x)
    # print(r.encoding)

    data = r.text
    soup = bs(r.text, 'html.parser')
    # print(data)
    # print(soup.prettify())

    #

    a = soup.find("ul", class_="newsList")
    # print(type(a))
    for i in a.children:
        if i.name == 'li':
            # print(type(i))
            for j in i.children:
                if j.name == "span":
                    time = j.text
                    # print('time=', time)
                    print(time)
                elif j.name == "a":
                    name = j.string
                    name = re.sub("[^a-zA-Z0-9\u4e00-\u9fa5]", '', name)
                    # print('name=',name)
                    print(name)
                    href = 'https://www.anxiang.gov.cn/' + j['href']
                    # print('href=',href)
                    print(href)
                    m = m +1
print(m)



